home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / Kant Pro source Folder / Kant Pro 1.1 ƒ / Shell ƒ / window layer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  7.8 KB  |  328 lines  |  [TEXT/MMCC]

  1. #define USE_FLOATING_WINDOWS    0        /* set to 1 for window layers */
  2.  
  3. #include "window layer.h"
  4.  
  5. static    WindowPtr MyNewWindowDispatch(short layer, Boolean useColor,
  6.                 ExtendedWindowPtr storage, const Rect *boundsRect, ConstStr255Param title,
  7.                 short procID, Boolean goAwayFlag, long refCon);
  8. static    void SetFrontWindowInLayer(WindowPtr newWindow, WindowPtr oldFrontWindow,
  9.                 short layer);
  10. static    WindowPtr GetFrontWindowInLayer(short layer);
  11. static    void SetWindowPrevious(WindowPtr window, WindowPtr previousWindow);
  12. static    WindowPtr GetWindowPrevious(WindowPtr window);
  13. static    void SetWindowNext(WindowPtr window, WindowPtr nextWindow);
  14. static    WindowPtr GetWindowNext(WindowPtr window);
  15. static    void SetWindowLayer(WindowPtr window, short layer);
  16. static    short GetWindowLayer(WindowPtr window);
  17. static    pascal void MyHiliteWindow(WindowPtr theWindow, Boolean fHilite);
  18. static    void ActivateWindow(WindowPtr window, Boolean activate);
  19.  
  20. enum    /* window layers */
  21. {
  22.     kFloatLayer=0, kDocumentLayer
  23. };
  24.  
  25. #define NUM_LAYERS        2
  26. #define kMagicNumber    0x16435934
  27.  
  28. static    WindowPtr            gFrontWindowInLayer[NUM_LAYERS];
  29. static    UniversalProcPtr    gOldHiliteRoutine;
  30.  
  31. Boolean            gIgnoreNextActivateEvent;
  32.  
  33. void InitTheWindowLayer(void)
  34. {
  35. #if USE_FLOATING_WINDOWS
  36.     short            i;
  37.     
  38.     for (i=0; i<NUM_LAYERS; i++)
  39.         gFrontWindowInLayer[i]=0L;
  40.     
  41.     InstallHilitePatch();
  42. #endif
  43.     gIgnoreNextActivateEvent=FALSE;
  44. }
  45.  
  46. void ShutDownTheWindowLayer(void)
  47. {
  48. // well, no
  49. }
  50.  
  51. WindowPtr MyNewWindow(void *wStorage, const Rect *boundsRect, ConstStr255Param title,
  52.     Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon)
  53. {
  54.     return MyNewWindowDispatch(kDocumentLayer, FALSE, (ExtendedWindowPtr)wStorage, boundsRect,
  55.         title, procID, goAwayFlag, refCon);
  56. }
  57.  
  58. WindowPtr MyNewCWindow(void *wStorage, const Rect *boundsRect, ConstStr255Param title,
  59.     Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon)
  60. {
  61.     return MyNewWindowDispatch(kDocumentLayer, TRUE, (ExtendedWindowPtr)wStorage, boundsRect,
  62.         title, procID, goAwayFlag, refCon);
  63. }
  64.  
  65. WindowPtr MyNewFloatWindow(void *wStorage, const Rect *boundsRect, ConstStr255Param title,
  66.     Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon)
  67. {
  68.     return MyNewWindowDispatch(kFloatLayer, FALSE, (ExtendedWindowPtr)wStorage, boundsRect,
  69.         title, procID, goAwayFlag, refCon);
  70. }
  71.  
  72. WindowPtr MyNewFloatCWindow(void *wStorage, const Rect *boundsRect, ConstStr255Param title,
  73.     Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon)
  74. {
  75.     return MyNewWindowDispatch(kFloatLayer, TRUE, (ExtendedWindowPtr)wStorage, boundsRect,
  76.         title, procID, goAwayFlag, refCon);
  77. }
  78.  
  79. WindowPtr MyNewWindowDispatch(short layer, Boolean useColor,
  80.     ExtendedWindowPtr storage, const Rect *boundsRect, ConstStr255Param title, short procID,
  81.     Boolean goAwayFlag, long refCon)
  82. {
  83.     WindowPtr        window;
  84.     WindowPtr        oldFrontWindow;
  85.     WindowPtr        behind;
  86. #if USE_FLOATING_WINDOWS
  87.     WindowPtr        iter, nextIter;
  88. #endif
  89.         
  90.     behind=(WindowPtr)-1L;
  91. #if USE_FLOATING_WINDOWS
  92.     if (layer==kDocumentLayer)
  93.     {
  94.         iter=GetFrontWindowInLayer(kFloatLayer);
  95.         if (iter!=0L)
  96.         {
  97.             while ((nextIter=GetWindowNext(iter))!=0L)
  98.                 iter=nextIter;
  99.             behind=iter;
  100.         }
  101.     }
  102. #else
  103.     layer=kDocumentLayer;
  104. #endif
  105.     
  106.     window=useColor ?
  107.             NewCWindow(storage, boundsRect, title, TRUE, procID, behind, goAwayFlag, refCon) :
  108.             NewWindow(storage, boundsRect, title, TRUE, procID, behind, goAwayFlag, refCon);
  109.     
  110.     oldFrontWindow=GetFrontWindowInLayer(layer);
  111.     
  112. #if USE_FLOATING_WINDOWS
  113.     RemoveHilitePatch();
  114.     if ((layer==kDocumentLayer) && (oldFrontWindow!=0L))
  115.         HiliteWindow(oldFrontWindow, FALSE);
  116.     HiliteWindow(window, TRUE);
  117.     InstallHilitePatch();
  118.     
  119.     if ((layer==kFloatLayer) && (GetFrontDocumentWindow()!=0L))
  120.         gIgnoreNextActivateEvent=TRUE;
  121. #endif
  122.     
  123.     storage->magic=kMagicNumber;        /* so we know it's one of ours */
  124.     SetWindowLayer(window, layer);
  125.     SetFrontWindowInLayer(window, oldFrontWindow, layer);
  126.     
  127.     return window;
  128. }
  129.  
  130. void MyDisposeWindow(WindowPtr window)
  131. {
  132.     WindowPtr        newFrontWindow;
  133.     short            layer;
  134.     
  135.     if (WindowHasLayer(window))
  136.     {
  137.         layer=GetWindowLayer(window);
  138.         newFrontWindow=GetWindowNext(window);
  139.         if (newFrontWindow!=0L)
  140.             SetWindowPrevious(newFrontWindow, 0L);
  141.         gFrontWindowInLayer[layer]=newFrontWindow;
  142.         CloseWindow(window);
  143.         DisposePtr((Ptr)window);
  144.         window=0L;
  145. #if USE_FLOATING_WINDOWS
  146.         if (newFrontWindow!=0L)
  147.         {
  148.             RemoveHilitePatch();
  149.             HiliteWindow(newFrontWindow, TRUE);
  150.             InstallHilitePatch();
  151.         }
  152. #endif
  153.     }
  154.     else
  155.     {
  156.         DisposeWindow(window);
  157.     }
  158. }
  159.  
  160. Boolean MySelectWindow(WindowPtr window)
  161. {
  162.     WindowPtr        nextWindow, previousWindow, oldFrontWindow;
  163.     short            layer;
  164. #if USE_FLOATING_WINDOWS
  165.     WindowPtr        iter, nextIter;
  166. #endif
  167.     
  168.     if (WindowHasLayer(window))
  169.     {
  170.         layer=GetWindowLayer(window);
  171.         oldFrontWindow=GetFrontWindowInLayer(layer);
  172.         if (oldFrontWindow!=window)
  173.         {
  174.             nextWindow=GetWindowNext(window);            /* might be 0L */
  175.             previousWindow=GetWindowPrevious(window);    /* guaranteed !=0L */
  176.             SetWindowNext(previousWindow, nextWindow);
  177.             if (nextWindow!=0L)
  178.                 SetWindowPrevious(nextWindow, previousWindow);
  179.             SetFrontWindowInLayer(window, oldFrontWindow, layer);
  180.         }
  181.         
  182. #if USE_FLOATING_WINDOWS
  183.         if ((layer==kDocumentLayer) && ((iter=GetFrontWindowInLayer(kFloatLayer))!=0L))
  184.         {
  185.             while ((nextIter=GetWindowNext(iter))!=0L)
  186.                 iter=nextIter;
  187.             SendBehind(window, iter);
  188.         }
  189.         else
  190. #endif
  191.         {
  192.             SelectWindow(window);
  193.         }
  194.         
  195.         if (oldFrontWindow==window)
  196.             return FALSE;
  197.         
  198. #if USE_FLOATING_WINDOWS
  199.         RemoveHilitePatch();
  200.         if ((layer==kDocumentLayer) && (oldFrontWindow!=0L))
  201.         {
  202.             HiliteWindow(oldFrontWindow, FALSE);
  203.         }
  204.         HiliteWindow(window, TRUE);
  205.         InstallHilitePatch();
  206. #endif
  207.     }
  208.     else
  209.     {
  210.         SelectWindow(window);
  211.     }
  212.     
  213.     return TRUE;
  214. }
  215.  
  216. void SetFrontWindowInLayer(WindowPtr newWindow, WindowPtr oldFrontWindow,
  217.     short layer)
  218. {
  219.     if (newWindow!=0L)
  220.         SetWindowNext(newWindow, oldFrontWindow);
  221.     if (oldFrontWindow!=0L)
  222.         SetWindowPrevious(oldFrontWindow, newWindow);
  223.     if (newWindow!=0L)
  224.         SetWindowPrevious(newWindow, 0L);
  225.     gFrontWindowInLayer[layer]=newWindow;
  226. }
  227.  
  228. WindowPtr GetFrontWindowInLayer(short layer)
  229. {
  230.     return gFrontWindowInLayer[layer];
  231. }
  232.  
  233. void SetWindowPrevious(WindowPtr window, WindowPtr previousWindow)
  234. {
  235.     ((ExtendedWindowPtr)window)->previousWindow=previousWindow;
  236. }
  237.  
  238. WindowPtr GetWindowPrevious(WindowPtr window)
  239. {
  240.     return ((ExtendedWindowPtr)window)->previousWindow;
  241. }
  242.  
  243. void SetWindowNext(WindowPtr window, WindowPtr nextWindow)
  244. {
  245.     ((ExtendedWindowPtr)window)->nextWindow=nextWindow;
  246. }
  247.  
  248. WindowPtr GetWindowNext(WindowPtr window)
  249. {
  250.     return ((ExtendedWindowPtr)window)->nextWindow;
  251. }
  252.  
  253. void SetWindowLayer(WindowPtr window, short layer)
  254. {
  255.     ((ExtendedWindowPtr)window)->layer=layer;
  256. }
  257.  
  258. short GetWindowLayer(WindowPtr window)
  259. {
  260.     return ((ExtendedWindowPtr)window)->layer;
  261. }
  262.  
  263. Boolean WindowHasLayer(WindowPtr window)
  264. {
  265.     if (window==0L)
  266.         return FALSE;
  267.     else
  268.         return ((ExtendedWindowPtr)window)->magic==kMagicNumber;
  269. }
  270.  
  271. Boolean WindowIsFloat(WindowPtr window)
  272. {
  273. #if USE_FLOATING_WINDOWS
  274.     if (window!=0L)
  275.         return ((ExtendedWindowPtr)window)->layer==kFloatLayer;
  276.     else
  277. #endif
  278.         return FALSE;
  279. }
  280.  
  281. WindowPtr GetFrontDocumentWindow(void)
  282. {
  283. #if USE_FLOATING_WINDOWS
  284.     return GetFrontWindowInLayer(kDocumentLayer);
  285. #else
  286.     return FrontWindow();
  287. #endif
  288. }
  289.  
  290. WindowPtr GetIndWindowPtr(short index)
  291. {
  292.     WindowPtr        w;
  293.     short            i;
  294.     
  295.     for (i=NUM_LAYERS-1; i>=0; i--)
  296.     {
  297.         w=GetFrontWindowInLayer(i);
  298.         while ((w!=0L) && (GetWindowIndex(w)!=index))
  299.             w=GetWindowNext(w);
  300.         if (w!=0L)
  301.             return w;
  302.     }
  303.     
  304.     return 0L;
  305. }
  306.  
  307. void InstallHilitePatch(void)
  308. {
  309. #if USE_FLOATING_WINDOWS
  310.     UniversalProcPtr    newAddress;
  311.     
  312.     gOldHiliteRoutine=GetToolTrapAddress(_HiliteWindow);
  313.     newAddress=(UniversalProcPtr)StripAddress(MyHiliteWindow);
  314.     SetToolTrapAddress(newAddress, (short)_HiliteWindow);
  315. #endif
  316. }
  317.  
  318. void RemoveHilitePatch(void)
  319. {
  320. #if USE_FLOATING_WINDOWS
  321.     SetToolTrapAddress(gOldHiliteRoutine, (short)_HiliteWindow);
  322. #endif
  323. }
  324.  
  325. pascal void MyHiliteWindow(WindowPtr theWindow, Boolean fHilite)
  326. {
  327. }
  328.